using UnityEngine;

namespace QFramework.Framework.Util
{
    /**
     * 分辨率检测工具
     */
    public class ResolutionCheck
    {
        /**
         * 获取屏幕宽高比
         */
        public static float GetAspectRatio()
        {
            return Screen.width > Screen.height
                ? (float) Screen.width / Screen.height
                : (float) Screen.height / Screen.width;
        }

        /**
         * 是否是 Pad 分辨率 4 : 3
         */
        public static bool IsPadResolution()
        {
            var aspect = GetAspectRatio();
            return aspect > 4.0f / 3 - 0.05 && aspect < 4.0f / 3 + 0.05;
        }

        /**
         * 是否是 Phone 分辨率 16 : 9
         */
        public static bool IsPhoneResolution()
        {
            var aspect = GetAspectRatio();
            return aspect > 16.0f / 9 - 0.05 && aspect < 16.0f / 9 + 0.05;
        }

        /**
         * 是否是 iPhoneX 分辨率 2436 : 1125
         */
        public static bool IsiPhoneXResolution()
        {
            var aspect = GetAspectRatio();
            return aspect > 2436.0f / 1125 - 0.05 && aspect < 2436.0f / 1125 + 0.05;
        }
    }
}